#include <stdio.h>
#include <algorithm>
using std::sort;
using std::min;

/****************************
dp[i][j]: nums[i..n-1]拆分为j个子集的最小方差和
dp[i][j] = {
    (nums[n-1]-nums[i])^2   j=1, n-i>=1 => i<n, i>=m-1
    min((nums[k]-nums[i])^2+dp[k+1][j-1]) 
        m>=j>1, 0<=i<=k, n-k-1>=j-1 => i<=k<=n-j
}
****************************/

const int max_nums = 10000;
const int max_sets = 5000;
int nums[max_nums];
int dp[max_nums][max_sets+1];
inline int square(int n) { return n*n; } 

int main(void) {
    int cnt; // test case cnt
    int m, n;
    scanf("%d", &cnt);
    for(int idx1=1; idx1<=cnt; idx1++){
        scanf("%d%d", &n, &m);
        for(int idx2=0; idx2<n; idx2++) 
            scanf("%d", &nums[idx2]);
        sort(nums, nums+n);
        for(int i=m-1; i<n; i++) { //j=1
            dp[i][1] = square((nums[n-1]-nums[i]));
        }
        for(int j=2; j<=m; j++) {
            for(int i=0; i<=n-j; i++) {
                dp[i][j]= dp[i+1][j-1]; //k=i
                for(int k=i+1; k<=n-j; k++) {
                    dp[i][j]=min(dp[i][j], square(nums[k]-nums[i])+dp[k+1][j-1]);
                    
                }
            }
        }
        printf("Case %d: %d", idx1, dp[0][m]);
        
    }
    return 0;
}
